//Dom结构加载完成后执行
app.page.onReady = function () {

};

//页面所有元素加载完成
app.page.onLoad = function () {
    
    $app.mustInfo(function () {//获取请求必备参数
        console.log('app_device = ', $app.app_device);
    });

    // console.log('初始化',$app.navLength);
    ui.load({url : "nav2.html"});
    ui.load({url : "nav1.html"});


    setTimeout(function(){
        var navLength=$('footer').find('li').length;
        $app.navLength=navLength;//底部导航数量赋值给全局，方便调用
        // console.log('$app.navLength = ',$app.navLength);
    },300);
    
    
    
    //后退键
    var flag = 0;
    document.addEventListener("backbutton", function() {
        var navLen=$('#section_container').children('[data-nav]').length;
        var navXu=$('#section_container').children('[data-nav]').last().attr('data-nav');
        var navHad=$('#section_container').children('section').last().attr('data-nav');
        // console.log('navLen = ',navLen,navHad);
        //高亮状态为第1个nav
        if(navXu==1 && $app.judgeData(navHad)){
            console.log('back1')
            if (flag == 0) {
                app.hint("再按一次就退出应用了!");
                flag = flag + 1;
                //5s后重新设置回去
                setTimeout(function() {
                    flag = 0;
                }, 3000);
            } else if (flag == 1) {
                app.exit();//关闭应该
            }
        }else if(navLen<=$app.navLength && $app.judgeData(navHad)){
            ui.load({url : "nav1.html"});
            ui.closePopup();//关闭弹框
            $('#overlay,#easyDialogBox').remove();
            
            console.log('back2')
        }else{
            ui.Page.back();
            ui.closePopup();//关闭弹框
            $('#overlay,#easyDialogBox').remove();
            console.log('back3')
        }

    }, false);  
};